﻿using System;
using System.Runtime.InteropServices;

public class MessageHelper
{
	[DllImport("User32.dll")]
	private static extern bool SendMessage(int hWnd, int wMsg, IntPtr wParam, IntPtr lParam);
	//
	public const int WM_COPYDATA = 0x004a;

	[StructLayout(LayoutKind.Sequential)]
	public struct COPYDATASTRUCT
	{
		[MarshalAs(UnmanagedType.I4)]
		public int dwData;
		[MarshalAs(UnmanagedType.I4)]
		public int cbData;
		[MarshalAs(UnmanagedType.SysInt)]
		public IntPtr lpData;
	}

	public static bool sendWindowString(IntPtr hWnd, string msg)
	{
		IntPtr lpData = Marshal.StringToHGlobalUni(msg);

		COPYDATASTRUCT data = new COPYDATASTRUCT();
		data.dwData = 0;
		data.cbData = msg.Length * 2;
		data.lpData = lpData;

		IntPtr lpStruct = Marshal.AllocHGlobal(Marshal.SizeOf(data));

		Marshal.StructureToPtr(data, lpStruct, false);

		//int hTarget = Convert.ToInt32(textBox1.Text);
        return false;

		//SendMessage(hWnd, WM_COPYDATA, hWnd, lpStruct);
	}
}
